package algutil.partagemusic.bo;

import algutil.date.ConversionDate;
import algutil.fichier.ConversionFichier;

public class ScanRepoFile {

	private String repo;
	private String relativePath;
	// private long size;
	private long lastModified;

	public ScanRepoFile(String line, String repo) {
		this.repo = repo;
		relativePath = line.substring(repo.length(), line.indexOf(":", 2));
		// size = Long.parseLong(line.substring(line.indexOf(":", 2) + 1,
		// line.indexOf(":", line.indexOf(":", 2) + 1)));
		lastModified = Long
				.parseLong(line.substring(line.lastIndexOf(":") + 1));
	}

	public String toString() {
		return "[repo='" + repo + "';relativePath='" + relativePath
				+ "';lastMosified="
				+ ConversionDate.formatYYYYMMDD_HHMMSS(lastModified) +
				// ";size="+ ConversionFichier.tailleOctets2String(size) +
				"]";
	}

	public String getRepo() {
		return repo;
	}

	public String getRelativePath() {
		return relativePath;
	}

	/*
	 * public long getSize() { return size; }
	 */

	public long getLastModified() {
		return lastModified;
	}

	public int compareTo(ScanRepoFile srf) {

		int result = this.relativePath.compareTo(srf.getRelativePath());

		if (result == 0) {
			if (lastModified == srf.getLastModified()) {
				return 0;
			} else if (lastModified > srf.getLastModified()) {
				return 1;
			} else {
				return -1;
			}
		} else if (result > 0) {
			return 2;
		} else {
			return -2;
		}
	}

	public String getPath() {
		return repo + relativePath;
	}
}
